/**
 * 
 */
package br.srv.full.virtual.entities.persons;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.srv.full.virtual.entities.auth.Role;
import br.srv.full.virtual.entities.auth.User;

/**
 * @author Delfino
 * 
 */
@Entity
@Table(name = "workers")
// @IdClass(PkWorker.class)
public class Worker implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

//	 @Id
	@Column(name = "rolename", insertable = false, updatable = false)
	private String roleName;

//	@Id
	@Column(name = "userid", insertable = false, updatable = false)
	private Integer userId;

//	 @Id
	@Column(name = "clientid", insertable = false, updatable = false)
	private Integer clientId;

	@ManyToOne(targetEntity = Role.class, fetch = FetchType.EAGER, optional = false, cascade = { CascadeType.MERGE,
			CascadeType.REFRESH })
	@JoinColumn(name = "rolename", referencedColumnName = "rolename")
	private Role role;

	@ManyToOne(targetEntity = User.class, fetch = FetchType.EAGER, optional = false, cascade = { CascadeType.MERGE,
			CascadeType.REFRESH })
	@JoinColumn(name = "userid", referencedColumnName = "userid")
	private User user;

	@ManyToOne(targetEntity = Client.class, fetch = FetchType.EAGER, optional = false, cascade = { CascadeType.MERGE,
			CascadeType.REFRESH })
	@JoinColumn(name = "clientid", referencedColumnName = "clientid")
	private Client client;

	public Worker() {
		role = Role.CLIENT_WORKER;
	}

	/**
	 * @param p_client
	 * @param p_role
	 */
	public Worker(User p_user, Client p_client) {
		this();
		user = p_user;
		client = p_client;

	}

	/**
	 * @param p_client
	 * @param p_role
	 */
	public Worker(User p_user, Role p_role, Client p_client) {
		user = p_user;
		client = p_client;
		role = p_role;
	}

	/**
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * @param p_role
	 *            the role to set
	 */
	public void setRole(Role p_role) {
		role = p_role;
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param p_user
	 *            the user to set
	 */
	public void setUser(User p_user) {
		user = p_user;
	}

	//
	// /**
	// * @return the roleName
	// */
	// public String getRoleName() {
	// return roleName;
	// }
	//
	// /**
	// * @param p_roleName
	// * the roleName to set
	// */
	// public void setRoleName(String p_roleName) {
	// roleName = p_roleName;
	// }
	//
	/**
	 * @return the client
	 */
	public Client getClient() {
		return client;
	}

	/**
	 * @param p_clientsThatWork
	 *            the client to set
	 */
	public void setClient(Client p_clientsThatWork) {
		client = p_clientsThatWork;
	}

}
